package com.acyouzi.leetcode.greedy;

/**
 * Created by SUN on 2017/9/6.
 */
public class WiggleSubsequence {
  // https://leetcode.com/problems/wiggle-subsequence/description/
  public int wiggleMaxLength(int[] nums) {
    if (nums.length <= 1) return nums.length;
    int res = 2;
    for (int i = 1; i < nums.length-1; i++) {
      if (nums[i-1] < nums[i] && nums[i+1] < nums[i]) res ++;
      if (nums[i-1] > nums[i] && nums[i+1] > nums[i]) res ++;
    }
    return res;
  }
}
